-- NewSignInM
-- Created by chendh
-- 七日签到模块

module("NewSignInM", package.seeall);

-- 获取玩家已经签到的天数
function getSignInDays()
    return ME.user.dbase:query("sign_in_info").days;
end

-- 获取玩家已经签到的天数
function isFristWeek()
    local fristWeek = ME.user.dbase:query("sign_in_info").frist_week;
    if type(fristWeek) == "number" and fristWeek > 0 then
        return true;
    else
        return false;
    end
end

-- 获取玩家本周可以获得碎片的宠物
function getHeroId( ... )
    return ME.user.dbase:query("sign_in_info").hero_id;
end

-- 玩家当前是否可以签到
function canSignIn()
    if not DungeonAreaM.isDungeonPassed(ME.user, 11) then
        -- 尚未通关1-1，功能不开启
        return;
    end

    local signInInfo = ME.user.dbase:query("sign_in_info") or { };

    if not signInInfo.time then
        return true;
    else
        if TimeM.getServerTime() < ( signInInfo.next_time or 0 ) then
            return false;
        else
            return true;
        end
    end
end

-- 获取签到奖励信息
function getSignInBonus()
    local signInInfo = ME.user.dbase:query("sign_in_info");
    local bonusTab = {};

    for i=1, 7 do
        local bonus = FormulaM.invoke("CALC_SIGN_IN_BONUS", i, signInInfo);
        table.insert(bonusTab, bonus);
    end

    return bonusTab;
end

-- 签到
function signIn()
    Operation.cmd_sign_in();
end